package Classes.Tanks 
{
	import flash.geom.Point;
	import net.flashpunk.Entity;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.graphics.Image;

	/**
	 * ...
	 * @author Alex
	 */
	public class PlayerTank extends Tank
	{
		
		public function PlayerTank(startLocation:Point)
		{
			super(startLocation);
			type = ObjectTypes.PLAYER_TANK;
			var image:Image = new Image(TankImageList.GFX_PLAYER_TANK);
			setImage(image);
			setHitbox(image.width, image.height, x, y);
			setMoveBehaviour(new MoveWithTurrents());
			m_status = TankStatus.STOPPED;
		}
		
		private function updateMovement():void
		{			
			if (m_status != TankStatus.DEAD)
			{
				if (Input.check(Key.UP)) 
				{
					m_status = TankStatus.MOVING;
					setDirectionFacing(Direction.UP);
				}
				if (Input.check(Key.DOWN))
				{
					setDirectionFacing(Direction.DOWN);
					m_status = TankStatus.MOVING;
				}
				if (Input.check(Key.LEFT))
				{
					setDirectionFacing(Direction.LEFT);
					m_status = TankStatus.MOVING;
				}
				if (Input.check(Key.RIGHT)) 
				{
					setDirectionFacing(Direction.RIGHT);
					m_status = TankStatus.MOVING;
				}
			
				if (Input.check(Key.SPACE))
				{
					Shoot();
				}
			}
			
			if (m_status == TankStatus.MOVING)
				moveTankForward();
			
			
		}
		
		private function collisionHandling():void
		{
			var typesCollidedWith:Array = getCollisions();
			for each (var typeCollidedWith:Entity in typesCollidedWith)
			{
				if (typeCollidedWith.type == ObjectTypes.LEVEL)
					LevelCollisionHandling();
				if (typeCollidedWith.type == ObjectTypes.ENEMY_TANK)
					m_status = TankStatus.DEAD;
				if (typeCollidedWith.type == ObjectTypes.BULLET)
					m_status = TankStatus.DEAD;
			}
			
		}
		
		
		override public function update():void 
		{
			collisionHandling();			
			updateMovement();
			super.update();
		}
	}
	
}